﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entities;
using Utility;
using BUS;

public partial class A_LetsDeal_quanlyhoadon : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }

    protected void load_data()
     {
        pager.PageSize = 10;
        int total = 0;
        Criteria c = new Criteria();
        c.add(Condition.AND, Tbl_DonHang_Columns.NguoiDat, Condition.EQUAL, Tbl_KhachHang_BUS.GetByUsername(Session["username"].ToString()).STT);

        Tbl_DonHang_Collection dhCollection =
          Tbl_DonHang_BUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize,
          Tbl_DonHang_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);

        Repeater1.DataSource = dhCollection;
        Repeater1.DataBind();
        pager.ItemCount = total;

    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
                 e.Item.ItemType == ListItemType.Item)
        {
            Tbl_DonHang_Entities donhang = (Tbl_DonHang_Entities)e.Item.DataItem;
            Tbl_CTDH_Entities ctdh = Tbl_CTDH_BUS.GetByIDDH(donhang.STT);

            HyperLink hyp_madh = (HyperLink)e.Item.FindControl("hyp_madh");
            hyp_madh.Text = donhang.MaDH.ToString();
            hyp_madh.NavigateUrl = "~/A_LetsDeal/quanlyctdh.aspx?id=" + donhang.STT.ToString();

            Literal lit_ngaydat = (Literal)e.Item.FindControl("lit_ngaydat");
            lit_ngaydat.Text = donhang.NgayDat;

            Literal lit_sovc = (Literal)e.Item.FindControl("lit_sovc");
            lit_sovc.Text = ctdh.SoLuong.ToString();

            CheckBox cb_dagiao = (CheckBox)e.Item.FindControl("cb_dagiao");
            cb_dagiao.Checked = donhang.DaGiao;
        }
    }

    protected void bt_timkiem_Click(object sender, EventArgs e)
    {
        if (txt_timkiem.Text != "")
        {
            Response.Redirect("~/A_LetsDeal/Default.aspx?tensanpham=" + txt_timkiem.Text);
        }
    }
}
